/*
 * testClient.cpp
 *
 *  Created on: Feb 19, 2012
 *      Author: nikhil
 */
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <pthread.h>
#include <sys/signal.h>
#include <sys/time.h>
#include <sys/resource.h>
#include<iostream>
#include<fstream>
#include<string>
#include<exception>
#include<vector>
#include "FileUtilities.h"

using namespace std;
using namespace utilities;

#define	BUFSIZE 256
/*
int	connectTCP(const char *host, const char *service);
int main(int argc, char *argv[])
{
	char	*host = "localhost";	// host to use if none supplied
	char	*service = "9000";	// default service name
	char *fileName="sample.txt";
				//32-bit integer to hold time
	int	s, n;			// socket descriptor, read count

	char *buff=(char *)malloc(BUFSIZE);

	switch (argc) {
		case 1:
			host = "localhost";
			break;
		case 4:	fileName=argv[3];
					// FALL THROUGH
		case 3:
			service = argv[2];
			// FALL THROUGH
		case 2:
			host = argv[1];
			break;
		default:
			fprintf(stderr, "usage: UDPtime [host [port]]\n");
			exit(1);
	}

	char *cmd="acceptfile";
	s = connectTCP(host, service);
	printf("connevted\n");
	//write command
	//(void) write(s, cmd, strlen(cmd));
	(void) send(s, cmd, strlen(cmd),0);


	char *commandACK="cmdreceived";
	char  cmdACK[BUFSIZE];

	int len=0;
	//while( (len = read(s,cmdACK,BUFSIZE)) < 0);
	//int len=read(s,cmdACK,BUFSIZE);
		len=recv(s,cmdACK,BUFSIZE,0);

			cmdACK[len] = '\0';

	printf("\ncommand ACK is :%s\n",commandACK);
	printf("\ncmdACsddCSA is :%s\n",cmdACK);
	if(!strcmp(commandACK,cmdACK))
	{
	//write path
	char *venIdFPathChunkNo="ptest,k1/k2/sample.txt,2";
	//(void) write(s, venIdFPathChunkNo, strlen(venIdFPathChunkNo));
	(void) send(s, venIdFPathChunkNo, strlen(venIdFPathChunkNo),0);


	}
	else
	{
		fprintf(stderr,"Command not acknowledged\n");
		exit(1);
	}

	char *contentRequest="sendContent";
	char strContentReq[20];
	int len2=-1;
	//while( (len2 = read(s,strContentReq,strlen(strContentReq))) < 0);
	//int len2=read(s,strContentReq,strlen(strContentReq));
	len2=recv(s,strContentReq,11,0);

	strContentReq[len2] = '\0';

	cout<<"strContentReq = "<<strContentReq<<endl;

	FileUtilities* fu = new FileUtilities();
	int lenBytesREcvd=fu->readBytes(fileName,&buff);

	if(!strcmp(contentRequest,strContentReq))
	{
		printf("comparision CR succeeded\n");
		//char *data="received firsst edge server data";
		(void) write(s, buff,lenBytesREcvd);

	}
	else
	{
		printf("Content REquest not received\n");
		exit(1);
	}
	printf("Ended the start\n");
}
*/
